package tj.ums.com.intretech.tj.live.service

import com.intretech.tj.live.entity.DTO.VehicleStatus
import com.intretech.tj.live.service.Live0Service
import jakarta.enterprise.context.ApplicationScoped
import java.util.concurrent.ConcurrentHashMap

@ApplicationScoped
class LiveService {

    // 定义ROS车辆ID为 ROS1 - ROS5  ROS公交车为 ROS_BUS 警车 ROS_P 救护车 ROS_R 工程车 ROS_E 消防车  ROS_F
    // 定义路径规划车辆为 ROSLite_{TYPE}
    // 定义巡线车辆为 STM32_{TYPE}
    private val vehicleMap = ConcurrentHashMap<String, VehicleStatus>() // 车辆当前的信息
    private val live0Service = Live0Service()

    /**
     * 更新车辆状态信息
     */
    fun updateVehicleStates(vehicleStatus: VehicleStatus): Boolean {
        val prevNodeId = vehicleMap[vehicleStatus.vehicleId]?.currentNodeId
        vehicleMap[vehicleStatus.vehicleId] = vehicleStatus
        return prevNodeId != vehicleStatus.currentNodeId
    }

    /**
     * 获得 车辆ID 集合
     */
    fun getVehicleIds(): List<String> {
        val vehicleIds = vehicleMap.keys().toList()
        return vehicleIds
    }

    fun getVehicleCurrentNodeId(vehicleId: String): Int {
        return vehicleMap[vehicleId]?.currentNodeId ?: -1
    }

}